//获取办公室的销售提成
jQuery(document).ready(function() {

    //分公司fieldid
    var fgsField=WfForm.convertFieldNameToId("fgs");

    //操作日期
    var czrqField=WfForm.convertFieldNameToId("czrq");

    //分公司销售任务
      var fgsxsrwField = WfForm.convertFieldNameToId("fgsxsrw");
      //分公司销售业绩
      var fgsxsyjField = WfForm.convertFieldNameToId("fgsxsyj");
      //完成率
        var wclField=WfForm.convertFieldNameToId("wcl");

      //提成规则
      var xztcgzField=WfForm.convertFieldNameToId("xztcgz","detail_1");
    //奖金金额fielid
    var jjjeyField=WfForm.convertFieldNameToId("tcje","detail_1");
    //是否按全地区销售业绩计算
    var sfaqdqxsyjjsField=WfForm.convertFieldNameToId("sfaqdqxsyjjs");
    //销售业绩归属人
    var xsyjgsrField=WfForm.convertFieldNameToId("xsyjgsr");
    //小程序业绩
    var xcxyjField=WfForm.convertFieldNameToId("xcxyj");
    //alert(xsyjgsrField);
   // alert(fgsField);
    //分公司改变时,触发事件
  // WfForm.bindFieldChangeEvent(fgsField,xsyjgsrField,function(obj,id,value){
   WfForm.bindFieldChangeEvent("field42579,field18390",function(obj,id,value){
   //alert(value);

     //分公司值
       var fgsVal=WfForm.getFieldValue(fgsField);
        //操作日期值
        var czrqVal=WfForm.getFieldValue(czrqField);
        //是否按全地区销售业绩计算值
        var sfaqdqxsyjjsVal=WfForm.getFieldValue(sfaqdqxsyjjsField);
        //销售业绩归属人值
        var xsyjgsrVal=WfForm.getFieldValue(xsyjgsrField);

        //根据当前完成比和部门id
        jQuery.ajax({
            async: false,
            type: 'get',
            url: "/api/weavernorth/salary/retailmess",
            data: {
                "userid": fgsVal,
                "zdmc":"fgs",
                "czrq":czrqVal,
                 "fgsVal": fgsVal,
                 "sfaqdqxsyjjs":sfaqdqxsyjjsVal,
                 "xsyjgsr":xsyjgsrVal
            },
            success: function(data) {

                var data = JSON.parse(data);
                WfForm.changeFieldValue(fgsxsrwField, {
                    value: data.yrw
                });
                WfForm.changeFieldValue(fgsxsyjField, {
                    value: data.xlzls
                });
                 WfForm.changeFieldValue(xcxyjField, {
                                    value: data.xcxxszls
                                });

            }
        });

    });

    //当提成规则改变时,需要查询提成金额
    WfForm.bindDetailFieldChangeEvent(xztcgzField,
    function(id, index, value) {
     debugger;
       //完成率值
           var wclVal= WfForm.getFieldValue(wclField);
             //根据完成比和部门id
             jQuery.ajax({
                 async: false,
                 type: 'get',
                 url: "/api/weavernorth/salary/getOfficeTcje",
                 data: {
                    "wclVal":wclVal,
                    "tcge":value
                 },
                 success: function(data) {
                     var data = JSON.parse(data);
                     WfForm.changeFieldValue(jjjeyField + "_" + index, {
                         value:data
                     });


                 }
             });

    });
});

